<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title></title>
	<link rel="stylesheet" href="/public/layui/css/layui.css">
	<link rel="stylesheet" href="/public/css/common.css">
	<script src="/public/js/jquery.min.js"></script>
</head>
<body>
	<div class="page-content layui-anim layui-anim-upbit">
    <div class="layui-form">
			<input type="hidden" name="id" value="<%= id %>">
			<!-- 账号 -->
      <div class="layui-form-item">
        <label for="u_name" class="layui-form-label">
          <span>账号</span>
        </label>
        <div class="layui-input-inline">
          <input style="background: #eee;" type="text" disabled maxlength="12" id="ccount" name="ccount" value="<%= ccount %>" required lay-verify="ccount"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <!-- 用户名 -->
      <div class="layui-form-item">
        <label for="u_name" class="layui-form-label">
          <span class="x-red">*</span>
          <span>用户名</span>
        </label>
        <div class="layui-input-inline">
          <input type="text" maxlength="12" id="u_name" name="u_name" value="<%= name %>" required lay-verify="u_name"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <!-- 用户密码 -->
      <div class="layui-form-item">
        <label for="pass" class="layui-form-label">
          <span>用户密码</span>
        </label>
        <div class="layui-input-inline">
          <input type="password" placeholder="如果不填，则不修改此项" id="pass" aria-modal="21" name="pass" required lay-verify="pass"
            autocomplete="off" class="layui-input">
        </div>
      </div>
      <!-- 选择性别 -->
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
            <span>选择性别</span>
        </label>
        <div class="layui-input-inline">
            <select id="sex" name="sex" class="valid" lay-filter="sex">
							<option value="1">男</option>
							<% if(sex == '0') { %>
							<option value="0" selected >女</option>
							<% } else {%>
							<option value="0">女</option>
							<% } %>
            </select>
        </div>
      </div>
      
      <!-- 选择头像 -->
      <div class="user-img">
      </div>
      
      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label"></label>
        <button  class="layui-btn" lay-filter="update" lay-submit="">确认修改</button>
      </div>
    </div>
	</div>
</body>
<script src="/public/layui/layui.js"></script>
<script src="/public/js/api.js"></script>
<script>
	layui.use(['form','layer'], function(){
    $ = layui.jquery;
    var form = layui.form;
    var  layer = layui.layer;
    //自定义验证规则
    form.verify({
      u_name: function(val){
        if(val.length < 2){
          return '昵称至少得2个字符哦';
        }
      },
      pass: function(val){
				if(val){
					let reg = /(.+){6,12}$/;
					if(!reg.test(val)) {
						return '密码必须6到12位';
					}
				}
			},
		});
		form.on('submit(update)', function(data) {
			let d = data.field;
			_http.update_user(d, (res) => {
				if(res.code == 0) {
          layer.alert(res.msg, {
            skin: 'layui-layer-molv'
            ,closeBtn: 0
          }, function(){
            parent.location.href='/admin/user'
          });
        } else {
          layer.alert(res.msg, {icon: 6});
        }
			})
		})
  });
</script>
</html>
